﻿Public Class FormPqjc
    Public usr As String
    Dim dtPqjc As New DataTable
    Dim objProdInfo As New clsProdInfo
    Dim prod_ids As String
    Private Sub FormPqjc_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        initDt()
    End Sub

    Public Sub initDt()
        dtPqjc.Columns.Add("prod_id")
        dtPqjc.Columns.Add("prod_spec_id")
        dtPqjc.Columns.Add("prod_spec_name")
        dtPqjc.Columns.Add("steel_seal_no")
        dtPqjc.Columns.Add("pq_ope")
        dtPqjc.Columns.Add("pq_dt")
    End Sub

    Private Sub txtBarCode_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtBarCode.KeyPress
        If String.IsNullOrEmpty(txtBarCode.Text.Trim()) = False Then
            If e.KeyChar = vbCr Then
                Dim dt As DataTable = objProdInfo.getProdInfoByProdId(txtBarCode.Text.Trim(), "14")
                If dt.Rows.Count = 1 Then
                    Dim dr As DataRow() = dtPqjc.Select("prod_id='" & dt.Rows(0)("prod_id") & "'")
                    If dr.Length = 0 Then
                        dtPqjc.Rows.Add(dt.Rows(0)("prod_id"), dt.Rows(0)("prod_spec_id"), dt.Rows(0)("prod_spec_name"),
                                    dt.Rows(0)("steel_seal_no"), dt.Rows(0)("pq_ope"), dt.Rows(0)("pq_dt"))
                        prod_ids &= "'" & dt.Rows(0)("prod_id") & "',"
                        dgv.AutoGenerateColumns = False
                        dgv.DataSource = dtPqjc
                        txtBarCode.Text = String.Empty
                        txtBarCode.Focus()
                    Else
                        MsgBox("该标签号已在表格中存在！", vbYes, "提示")
                    End If
                Else
                    If dt.Rows.Count = 0 Then
                        MsgBox("未获取到接收状态下的此支座信息，请核查！", MsgBoxStyle.Information, "喷漆检测")
                    Else
                        MsgBox("此条码信息存在多条记录，请核查！", MsgBoxStyle.Information, "喷漆检测")
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If String.IsNullOrEmpty(usr) = False Then
            If dtPqjc.Rows.Count > 0 Then
                If MsgBox("确认保存喷漆检测吗？", vbYesNo, "提示") = vbYes Then
                    If prod_ids.Length > 0 Then
                        prod_ids = prod_ids.Substring(0, prod_ids.Length - 1)
                    End If
                    Dim rtn As Integer = objProdInfo.updateProdInfoPqjc(prod_ids, usr)
                    If rtn <> -2 Then
                        CType(Owner, FormMain).setDgvData()
                        MsgBox("保存成功", MsgBoxStyle.Information, "喷漆检测")
                        dtPqjc.Rows.Clear()
                        txtBarCode.Focus()
                    Else
                        MsgBox("保存失败", MsgBoxStyle.Information, "喷漆检测")
                    End If
                End If
            Else
                MsgBox("请扫描或输入标签号，进行完工保存", vbYes, "喷漆检测")
            End If
        Else
            MsgBox("请勾选用户", MsgBoxStyle.Information, "喷漆检测")
        End If
    End Sub


    Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
        If dgv.SelectedRows.Count > 0 Then
            dtPqjc.Rows.RemoveAt(dgv.CurrentRow.Index)
            dgv.AutoGenerateColumns = False
            dgv.DataSource = dtPqjc
        End If
    End Sub


End Class